

import ComponentBase from "../../../engine/ComponentBase";
import { Logger } from "../../../engine/Logger";
import { RoomConfig } from "../../config/RoomConfig";
import { UserModel } from "../../model/UserModel";
import { UIHelper } from "../../util/UIHelper";

const { ccclass, property } = cc._decorator;

@ccclass
export default class roomconfig_create extends ComponentBase {


    public roomConfig: RoomConfig = new RoomConfig();
    public renshu_toggleContainer: cc.ToggleContainer;
    public jushu_toggleContainer: cc.ToggleContainer;
    public difen_toggleContainer: cc.ToggleContainer;
    public fangfei_toggleContainer: cc.ToggleContainer
    public distance_limit_toggleContainer: cc.ToggleContainer
    private dismiss_time_toggleContainer: cc.ToggleContainer
    private tuoguan_toggleContainer: cc.ToggleContainer
    private tuoguan_time: cc.Node;
    private tuoguan_time_toggleContainer: cc.ToggleContainer

    private limit_emoji_toggle: cc.Toggle
    private limit_voice_toggle: cc.Toggle;
    private limitDropItem: cc.Toggle

    onEnable(): void {
        this.jushu_toggleContainer = this.getChild(this.node, "view/content/jushu/jushu_toggleContainer", cc.ToggleContainer)
        this.setToggleContainerIndex(this.jushu_toggleContainer, 0)
        this.renshu_toggleContainer = this.getChild(this.node, "view/content/renshu/renshu_toggleContainer", cc.ToggleContainer);
        this.setToggleContainerIndex(this.renshu_toggleContainer, 0)
     
        this.difen_toggleContainer = this.getChild(this.node, "view/content/difen/difen_toggleContainer", cc.ToggleContainer)
        this.setToggleContainerIndex(this.difen_toggleContainer, 0)
        this.fangfei_toggleContainer = this.getChild(this.node, "view/content/fangfei/fangfei_toggleContainer", cc.ToggleContainer)
        this.setToggleContainerIndex(this.fangfei_toggleContainer, 0)
        if (UserModel.instance.nowClub) {
            this.fangfei_toggleContainer.node.getChildByName("quanzhuToggle").active = true
        } else {
            this.fangfei_toggleContainer.node.getChildByName("quanzhuToggle").active = false;
        }
        this.distance_limit_toggleContainer = this.getChild(this.node, "view/content/distance_limit/distance_limit_toggleContainer", cc.ToggleContainer)
        this.setToggleContainerIndex(this.distance_limit_toggleContainer, 0)
        this.dismiss_time_toggleContainer = this.getChild(this.node, "view/content/dismiss_time/dismiss_time_toggleContainer", cc.ToggleContainer)
        this.setToggleContainerIndex(this.dismiss_time_toggleContainer, 0)
        this.tuoguan_toggleContainer = this.getChild(this.node, "view/content/tuoguan/tuoguan_toggleContainer", cc.ToggleContainer)
        this.setToggleContainerIndex(this.tuoguan_toggleContainer, 0)
        UIHelper.onAddToggleContainerEvent(this.tuoguan_toggleContainer, this.node, "roomconfig_create", "on_tuoguan_change")
        this.tuoguan_time = this.findChild(this.node, "view/content/tuoguan_time")
        this.tuoguan_time.active = true
        this.tuoguan_time_toggleContainer = this.getChild(this.tuoguan_time, "tuoguan_time_toggleContainer", cc.ToggleContainer)
        this.setToggleContainerIndex(this.tuoguan_time_toggleContainer, 0)

        
        this.limit_emoji_toggle = this.getChild(this.node, "view/content/other_limit/limit_emoji_toggle", cc.Toggle)
        this.limit_emoji_toggle.isChecked = false;
        this.limit_voice_toggle = this.getChild(this.node, "view/content/other_limit/limit_voice_toggle", cc.Toggle)
        this.limit_voice_toggle.isChecked = false;
        this.limitDropItem = this.getChild(this.node, "view/content/other_limit/limitDropItem", cc.Toggle)
        this.limitDropItem.isChecked = false;
    }

    private on_tuoguan_change(toggle: cc.Toggle) {
        let tuoguanIndex: number = this.getToggleContainerIndex(this.tuoguan_toggleContainer)
        if (tuoguanIndex == 0) {
            this.tuoguan_time.active = true
        } else {
            this.tuoguan_time.active = false
        }
    }


    public getRoomConfig() {
        let distance_limit_index: number = this.getToggleContainerIndex(this.distance_limit_toggleContainer)
        this.roomConfig.distance_limit = RoomConfig.distance_limit_Config[distance_limit_index]
        let dismiss_time_index: number = this.getToggleContainerIndex(this.dismiss_time_toggleContainer)
        this.roomConfig.dismiss_time = RoomConfig.dismiss_time_config[dismiss_time_index]
        let tuoguanIndex: number = this.getToggleContainerIndex(this.tuoguan_toggleContainer)
        if (tuoguanIndex == 0) {
            let tuoguan_time_index: number = this.getToggleContainerIndex(this.tuoguan_time_toggleContainer)
            this.roomConfig.tuoguan_time = RoomConfig.tuoguan_time_config[tuoguan_time_index]
        } else {
            this.roomConfig.tuoguan_time = 0
        }

        if (this.limit_emoji_toggle.isChecked) {
            this.roomConfig.limit_emoji = 1
        } else {
            this.roomConfig.limit_emoji = 0
        }
        if (this.limit_voice_toggle.isChecked) {
            this.roomConfig.limit_voice = 1
        } else {
            this.roomConfig.limit_voice = 0
        }
        if (this.limitDropItem.isChecked) {
            this.roomConfig.limitDropItem = 1
        } else {
            this.roomConfig.limitDropItem = 0
        }
       
        return this.roomConfig
    }

}
